package com.leyou.item.web;

import com.leyou.order.pojo.SpecGroup;
import com.leyou.order.pojo.SpecParam;
import com.leyou.item.service.SpecificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("spec")
public class SpecificationController {

    @Autowired
    private SpecificationService specificationService;

    /**
     * 根据分类id查询分组
     * @param cid
     * @return
     */
    @GetMapping("groups/{cid}")
    public ResponseEntity<List<SpecGroup>> queryGroupsByCid(@PathVariable("cid")Long cid){
        return ResponseEntity.ok(specificationService.queryGroupsByCid(cid));
    }

    /**
     * 根据组id查询参数
     * @param gid
     * @return
     */
    @GetMapping("/params")
    public ResponseEntity<List<SpecParam>> queryParamByGid(
            @RequestParam(value = "gid",required = false) Long gid,
            @RequestParam(value = "cid",required = false) Long cid,
            @RequestParam(value = "searching",required = false) Boolean searching

    ){
        return ResponseEntity.ok(specificationService.queryParamByGid(gid,cid,searching));
    }

    /**
     * 根据分类查询规格组和组内参数
     **/
    @GetMapping("/group")
    public ResponseEntity<List<SpecGroup>> queryGroupWithParamListByCid(@RequestParam("cid") Long cid){
        return ResponseEntity.ok(specificationService.queryGroupWithParamListByCid(cid));
    }
}